<?php

namespace app\admin\model\shopro\user;

use app\admin\model\shopro\Common;

class WalletLog extends Common
{
    protected $name = 'shopro_user_wallet_log';

    protected $updateTime = false;

    protected $type = [
        'ext' => 'json'
    ];
    // 追加属性
    protected $append = [
        'event_text'
    ];

    const TYPE_MAP = [
        'money' => '消费券',
        'score' => '贡献值',
        'commission' => '福利券',
        'tokens'=>'通证',
        'gold_bean'  => '金豆',
        'shopping_score' => '购物积分'
    ];

    protected $eventMap = [
        'score' => [
            'signin' => '签到-赠送贡献值',
            'replenish_signin' => '签到-补签',
            'activity_gift' => '活动-赠送贡献值',
            'score_shop_pay' => '贡献值商城-贡献值支付',
            'order_pay' => '商城订单-贡献值抵扣',
            'order_refund' => '订单退款-退还贡献值',
            'admin_recharge' => '平台-贡献值充值',
            'recharge_gift' => '线上充值-赠送贡献值',
            'lucky_income'=>'预购成功-奖励贡献值',
            'release_day'=>'贡献值释放-扣除',
        ],
        'money' => [
            'order_pay' => '商城订单-消费券支付',
            'order_recharge' => '线上充值',
            'admin_recharge' => '平台-消费券充值',
            'recharge_gift' => '线上充值-赠送消费券',
            'activity_gift' => '活动-赠送消费券',
            'order_refund' => '订单退款-退还消费券',
            'transfer_by_commission' => '福利券-转入到消费券',
            'transfer_by_bean' => '金豆-转入到消费券',
            'lucky_pay' => '商品预购-消费券支付',
            'lucky_pay_back' => '商品预购撤回-消费券撤回',
            'lucky_income'=>'预购不成功-消费券退还',
            'withdraw' => '消费券兑换',
            'withdraw_exit' => '消费券兑换-退回',
        ],
        'balance' => [
            'order_pay' => '商城订单-余额支付',
            'order_recharge' => '线上充值',
            'admin_recharge' => '平台-余额充值',
            'recharge_gift' => '线上充值-赠送余额',
            'activity_gift' => '活动-赠送余额',
            'order_refund' => '订单退款-退还余额',
            'transfer_by_commission' => '福利券-转入到余额',
            'lucky_pay' => '商品预购-余额支付',
            'lucky_pay_back' => '商品预购撤回-余额撤回',
            'lucky_income'=>'预购不成功-余额退还',
            'withdraw' => '余额兑换',
            'withdraw_exit' => '余额兑换-退回',
        ],
        'commission' => [
            'withdraw' => '福利券兑换',
            'withdraw_error' => '兑换失败-返还福利券',
            'reward_income' => '福利券-直推收益',
            'reward_back' => '福利券-退还',
            'transfer_to_money' => '福利券-转出到消费券',
            'transaction_exp' => '通证买入-支出',
            'transaction_income'=>'通证卖出-收入',
            'transaction_close' => '通证买入-取消退回',
            'range_income'=>'福利券-团队收益',
            'equal_income'=>'福利券-平级收益',
            'lucky_income'=>'预购不成功-奖励福利券',
            'admin_recharge'=>'平台-福利券充值',
            'withdraw_exit' => '福利券兑换',
            'auto_buy'  => '开通或续费自动预约',
            'order_pay' => '商城订单-福利券支付',
        ],
        'tokens' =>[
            'transaction_buy'=>'通证交易-买入',
            'transaction_sell' => '通证交易-卖出',
            'transaction_close'=>'通证交易-取消退回',
            'transaction_auto_close'=>'通证交易-自动关闭订单',
            'withdrawal_destruction'=>'福利券兑换-销毁',
            'withdrawal_money_destruction'=>'福利券转消费券-销毁',
            'withdrawal_exit'=>'福利券兑换-销毁退回',
            'score_release'=>'贡献值释放-收入',
            'score_range_release'=>'贡献值团队释放-收入',
            'score_node_release'=>'贡献值全网释放-节点收入',
            'admin_recharge'=>'平台-通证充值',
            'token_pledge' => "通证质押",
            'token_pledge_finish' => "通证质押结束",
            'order_pay' => '商城订单-通证支付',

        ],
        'gold_bean' =>[
            'admin_recharge'=>'平台-金豆充值',
            "transaction_income" => "通证卖出-收入",
            'withdraw' => '兑换',
            "withdraw_error" => '金豆兑换-退回',
            'lucky_pay' => '商品预购-金豆支付',
            'lucky_income'=>'预购不成功-金豆退还',
            'order_pay' => '商城订单-金豆支付',
            'transaction_exp' => '通证买入-支出',
            'transaction_close' => '通证买入-取消退回',
            'transfer_to_money' => '金豆-转出到消费券',
        ],
        'shopping_score' =>[
            'admin_recharge'=>'平台-购物积分充值',
            'withdraw' => '兑换',
            'lucky_pay' => '商品预购-购物积分支付',
            'lucky_income'=>'预购不成功-购物积分退还',
            'order_pay' => '商城订单-购物积分支付',
        ]
    ];

    public function getEventMap() {
        return $this->eventMap;
    }

    public function scopeMoney($query)
    {
        return $query->where('type', 'money');
    }

    public function scopeCommission($query)
    {
        return $query->where('type', 'commission');
    }

    public function scopeGold_bean($query)
    {
        return $query->where('type', 'gold_bean');
    }
    public function scopeShopping_score($query)
    {
        return $query->where('type', 'shopping_score');
    }
    
    
    public function scopeBalance($query)
    {
        return $query->where('type', 'balance');
    }

    public function scopeScore($query)
    {
        return $query->where('type', 'score');
    }
    public function scopeTokens($query)
    {
        return $query->where('type', 'tokens');
    }

    public function getEventTextAttr($value, $data)
    {
        return $this->eventMap[$data['type']][$data['event']] ?? '';
    }
}
